package com.bat.client.controller;

import com.bat.util.R;
import com.bat.vo.TestFastJsonVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;

/**
 * @program: eureka-server
 * @description:
 * @author: zhoupengfei
 * @create: 2019-09-12 16:20
 **/
@RestController
@Slf4j
@Api("测试")
@Validated
@RequestMapping("/")
public class HomeController {
    public HomeController() {
        log.info("no lazy================");
    }

    @ApiOperation("首页")
    @RequestMapping(value = "/index",method = RequestMethod.GET)
    public R index(){
        return R.s();
    }

    @ApiOperation("测试参数校验")
    @RequestMapping(value = "/testValid",method = RequestMethod.GET)
    public R<String> testValid(@Validated @ApiParam("参数校验") @NotEmpty @RequestParam(required = false) String param){
        return  R.s();
    }

    @ApiOperation("测试fastjson出参转换")
    @GetMapping("/testFastJsonVo")
    public R<TestFastJsonVo> testFastJsonVo(){
        TestFastJsonVo testFastJsonVo=new TestFastJsonVo();
        testFastJsonVo.setId(22);
        testFastJsonVo.setName("测试fastjson");
        return R.s(testFastJsonVo);
    }
    @ApiOperation("测试fastjson入参转换")
    @PostMapping("/testFastJsonInvokeVo")
    public R<TestFastJsonVo> testFastJsonInvokeVo(@RequestBody TestFastJsonVo testFastJsonVo){
        testFastJsonVo.setId(22);
        testFastJsonVo.setName("测试fastjson");
        return R.s(testFastJsonVo);
    }

}